/*
 * SparqlQueryPanel.java
 *
 * Created on 8. Juni 2008, 23:48
 */

package twi.view;

import jtools.gui.CodeCompletionTextArea;
import twi.KeySearch;
import twi_project.TWI;

/**
 * 
 * @author Soeren
 */
public class SparqlQueryPanel extends javax.swing.JPanel implements QueryPanel{

	/** Creates new form SparqlQueryPanel */
	public SparqlQueryPanel() {
		initComponents();
		((CodeCompletionTextArea) this.jTextArea_sparql).setWordList(KeySearch
				.getCompleteVocabulary(TWI.getInstance().getOntologieModel()));
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed" desc="Generated
	// Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		jSplitPane1 = new javax.swing.JSplitPane();
		jPanel1 = new javax.swing.JPanel();
		jScrollPane1 = new javax.swing.JScrollPane();
		jTextArea_help = new javax.swing.JTextArea();
		jPanel2 = new javax.swing.JPanel();
		jLabel1 = new javax.swing.JLabel();
		jScrollPane2 = new javax.swing.JScrollPane();
		jTextArea_sparql = new CodeCompletionTextArea();
		jButton_exec = new javax.swing.JButton();
		jButton_save_quer = new javax.swing.JButton();
		jButton_save_temp = new javax.swing.JButton();

		jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
		jSplitPane1.setName("jSplitPane1"); // NOI18N
		jSplitPane1.setOneTouchExpandable(true);

		jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("help"));
		jPanel1.setName("jPanel1"); // NOI18N

		jScrollPane1.setEnabled(false);
		jScrollPane1.setName("jScrollPane1"); // NOI18N

		jTextArea_help.setColumns(20);
		jTextArea_help.setEditable(false);
		jTextArea_help.setRows(5);
		jTextArea_help.setName("jTextArea_help"); // NOI18N
		jScrollPane1.setViewportView(jTextArea_help);

		javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(
				jPanel1);
		jPanel1.setLayout(jPanel1Layout);
		jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 366,
				Short.MAX_VALUE));
		jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 70,
				Short.MAX_VALUE));

		jSplitPane1.setTopComponent(jPanel1);

		jPanel2.setEnabled(false);
		jPanel2.setName("jPanel2"); // NOI18N

		jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18));
		jLabel1.setText("Sparql Query");
		jLabel1.setName("jLabel1"); // NOI18N

		jScrollPane2.setName("jScrollPane2"); // NOI18N

		jTextArea_sparql.setColumns(20);
		jTextArea_sparql.setRows(5);
		jTextArea_sparql
				.setText("SELECT ?obj ?pre ?sub \nWHERE { ?obj ?pre ?sub. }");
		jTextArea_sparql.setName("jTextArea_sparql"); // NOI18N
		jTextArea_sparql.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseEntered(java.awt.event.MouseEvent evt) {
				jTextArea_sparqlMouseEntered(evt);
			}
		});
		jScrollPane2.setViewportView(jTextArea_sparql);

		jButton_exec.setText("Execute Query");
		jButton_exec.setName("jButton_exec"); // NOI18N
		jButton_exec.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseEntered(java.awt.event.MouseEvent evt) {
				jButton_execMouseEntered(evt);
			}
		});
		jButton_exec.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton_execActionPerformed(evt);
			}
		});

		jButton_save_quer.setText("Save Query");
		jButton_save_quer.setName("jButton_save_quer"); // NOI18N
		jButton_save_quer.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseEntered(java.awt.event.MouseEvent evt) {
				jButton_save_querMouseEntered(evt);
			}
		});
		jButton_save_quer
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						jButton_save_querActionPerformed(evt);
					}
				});

		jButton_save_temp.setText("Save As Template");
		jButton_save_temp.setName("jButton_save_temp"); // NOI18N
		jButton_save_temp.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseEntered(java.awt.event.MouseEvent evt) {
				jButton_save_tempMouseEntered(evt);
			}
		});
		jButton_save_temp
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						jButton_save_tempActionPerformed(evt);
					}
				});

		javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(
				jPanel2);
		jPanel2.setLayout(jPanel2Layout);
		jPanel2Layout
				.setHorizontalGroup(jPanel2Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel2Layout.createSequentialGroup().addGap(
										118, 118, 118).addComponent(jLabel1)
										.addContainerGap(147, Short.MAX_VALUE))
						.addComponent(jScrollPane2,
								javax.swing.GroupLayout.DEFAULT_SIZE, 382,
								Short.MAX_VALUE)
						.addGroup(
								jPanel2Layout
										.createSequentialGroup()
										.addComponent(jButton_save_temp)
										.addGap(32, 32, 32)
										.addComponent(jButton_save_quer)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED,
												37, Short.MAX_VALUE)
										.addComponent(jButton_exec)));
		jPanel2Layout
				.setVerticalGroup(jPanel2Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel2Layout
										.createSequentialGroup()
										.addContainerGap()
										.addComponent(jLabel1)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(
												jScrollPane2,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												126,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												jPanel2Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																jButton_save_temp)
														.addComponent(
																jButton_exec)
														.addComponent(
																jButton_save_quer))
										.addContainerGap(33, Short.MAX_VALUE)));

		jSplitPane1.setRightComponent(jPanel2);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 384,
				Short.MAX_VALUE));
		layout.setVerticalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 334,
				Short.MAX_VALUE));
	}// </editor-fold>//GEN-END:initComponents

	private void jTextArea_sparqlMouseEntered(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_jTextArea_sparqlMouseEntered
	// TODO add your handling code here:
	}// GEN-LAST:event_jTextArea_sparqlMouseEntered

	private void jButton_save_tempMouseEntered(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_jButton_save_tempMouseEntered
	// TODO add your handling code here:
	}// GEN-LAST:event_jButton_save_tempMouseEntered

	private void jButton_save_querMouseEntered(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_jButton_save_querMouseEntered
	// TODO add your handling code here:
	}// GEN-LAST:event_jButton_save_querMouseEntered

	private void jButton_execMouseEntered(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_jButton_execMouseEntered
	// TODO add your handling code here:
	}// GEN-LAST:event_jButton_execMouseEntered

	private void jButton_execActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton_execActionPerformed
		String sparql = this.jTextArea_sparql.getText();
		TWI.getInstance().executeQuery(sparql, true);
	}// GEN-LAST:event_jButton_execActionPerformed

	private void jButton_save_querActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton_save_querActionPerformed
	// TODO add your handling code here:
	}// GEN-LAST:event_jButton_save_querActionPerformed

	private void jButton_save_tempActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton_save_tempActionPerformed
		new SaveSparqlTemplate(null, true, this.jTextArea_sparql.getText())
				.setVisible(true);
	}// GEN-LAST:event_jButton_save_tempActionPerformed

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JButton jButton_exec;
	private javax.swing.JButton jButton_save_quer;
	private javax.swing.JButton jButton_save_temp;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JPanel jPanel1;
	private javax.swing.JPanel jPanel2;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JScrollPane jScrollPane2;
	private javax.swing.JSplitPane jSplitPane1;
	private javax.swing.JTextArea jTextArea_help;
	private javax.swing.JTextArea jTextArea_sparql;
	// End of variables declaration//GEN-END:variables
	@Override
	public void setFocus() {
		// TODO Auto-generated method stub
		
	}

}
